package Test.D4;

/**
 * 练习 用户名和密码判断测试
 */
public class UserLoad
{
    public static void main(String[] args) {
        /*
         * 局部类 测试用例数据，仅仅用于在这里测试，所以定义为局部类
         */
        class TestUser
        {
            public String mName,mPass;
            public TestUser(String name,String pass)
            {mName = name;
                mPass = pass;
            }
            @Override
            public String toString() {
                // TODO Auto-generated method stub
                return "测试用例： 用户名:"+mName+"\n密码:"+mPass+"\n";
            }
        }

        /**
         * 测试用例数组
         */
        TestUser[] testUsers = {
            new TestUser(null, null),
            new TestUser(null, "123"),
            new TestUser("name1", null),
            new TestUser("name1", "123"),
            new TestUser("testname1", "123"),
            new TestUser("name1", "1234567"),
            new TestUser("testname1", "1234567"),
            new TestUser("testname1", "1234567kkkkkkkkkkkkkkk"),
            new TestUser("testname3333333333333dddd1", "1234567kkkkkkkkkkkkkkk"),
        };

        UserLoad userLoad = new UserLoad();
        /*循环测试用例，测试登录数据 */
        for(int i=0;i<testUsers.length;i++)
        {
            try {
                userLoad.load(testUsers[i].mName, testUsers[i].mPass);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                System.out.println(testUsers[i].toString()+"错误信息:"+e.getMessage()+"\n\n");
            }
        }
    }
    /**
     * 登录功能
     * @param name 用户名
     * @param pass 密码
     * @throws Exception 抛出异常
     */
    public void load(String name,String pass) throws Exception
    {
        if(name==null||pass==null)
        {
            throw new Exception("用户名或者密码不能为空 !!! ");
        }
        else if(name.length()<6||pass.length()<6)
        {
            throw new Exception("用户名或者密码长度必须大于6位 !!! ");
        }
        else if(name.length()>15||pass.length()>15)
        {
            throw new Exception("用户名或者密码长度必须小于15位 !!! ");
        }
        else 
        {
            System.out.println("用户名:"+name+"\n密码:"+pass+"\n满足要求\n\n");
        }
    }
}